package org.bytesoft.openjta.archive;

import java.io.Serializable;

public abstract class AbstractArchive implements Serializable {
	private static final long serialVersionUID = 1L;

	protected boolean prepareStarted;
	protected BooleanResult prepareResult;
	protected boolean commitStarted;
	protected BooleanResult commitResult;
	protected boolean rollbackStarted;
	protected BooleanResult rollbackResult;

	public void setPrepareResult(boolean success) {
		if (success) {
			this.prepareResult = BooleanResult.positive;
		} else {
			this.prepareResult = BooleanResult.negative;
		}
	}

	public void setCommitResult(boolean success) {
		if (success) {
			this.commitResult = BooleanResult.positive;
		} else {
			this.commitResult = BooleanResult.negative;
		}
	}

	public void setRollbackResult(boolean success) {
		if (success) {
			this.rollbackResult = BooleanResult.positive;
		} else {
			this.rollbackResult = BooleanResult.negative;
		}
	}

	public boolean isPrepareSuccess() {
		return this.prepareStarted && BooleanResult.positive.equals(this.prepareResult);
	}

	public boolean isCommitSuccess() {
		return this.commitStarted && BooleanResult.positive.equals(this.commitResult);
	}

	public boolean isRollbackSuccess() {
		return this.rollbackStarted && BooleanResult.positive.equals(this.rollbackResult);
	}

	public boolean isPrepareFailure() {
		return this.prepareStarted && BooleanResult.negative.equals(this.prepareResult);
	}

	public boolean isCommitFailure() {
		return this.commitStarted && BooleanResult.negative.equals(this.commitResult);
	}

	public boolean isRollbackFailure() {
		return this.rollbackStarted && BooleanResult.negative.equals(this.rollbackResult);
	}

	public boolean isPrepareCompleted() {
		return this.isPrepareSuccess() || this.isPrepareFailure();
	}

	public boolean isCommitCompleted() {
		return this.isCommitSuccess() || this.isCommitFailure();
	}

	public boolean isRollbackCompleted() {
		return this.isRollbackSuccess() || this.isRollbackFailure();
	}

	public boolean isPrepareStarted() {
		return prepareStarted;
	}

	public void setPrepareStarted(boolean prepareStarted) {
		this.prepareStarted = prepareStarted;
	}

	public BooleanResult getPrepareResult() {
		return prepareResult;
	}

	public void setPrepareResult(BooleanResult prepareResult) {
		this.prepareResult = prepareResult;
	}

	public boolean isCommitStarted() {
		return commitStarted;
	}

	public void setCommitStarted(boolean commitStarted) {
		this.commitStarted = commitStarted;
	}

	public BooleanResult getCommitResult() {
		return commitResult;
	}

	public void setCommitResult(BooleanResult commitResult) {
		this.commitResult = commitResult;
	}

	public boolean isRollbackStarted() {
		return rollbackStarted;
	}

	public void setRollbackStarted(boolean rollbackStarted) {
		this.rollbackStarted = rollbackStarted;
	}

	public BooleanResult getRollbackResult() {
		return rollbackResult;
	}

	public void setRollbackResult(BooleanResult rollbackResult) {
		this.rollbackResult = rollbackResult;
	}
}
